home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / system-config-printer / troubleshoot / ErrorLogFetch.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-10-12  |  3.9 KB  |  131 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import cups
  5. import os
  6. import tempfile
  7. import time
  8. from timedops import TimedOperation
  9. from base import *
  10.  
  11. class ErrorLogFetch(Question):
  12.     
  13.     def __init__(self, troubleshooter):
  14.         Question.__init__(self, troubleshooter, 'Error log fetch')
  15.         troubleshooter.new_page(gtk.Label(), self)
  16.         self.persistent_answers = { }
  17.  
  18.     
  19.     def display(self):
  20.         answers = self.troubleshooter.answers
  21.         parent = self.troubleshooter.get_window()
  22.         self.answers = { }
  23.         
  24.         try:
  25.             checkpoint = answers['error_log_checkpoint']
  26.         except KeyError:
  27.             checkpoint = None
  28.  
  29.         if self.persistent_answers.has_key('error_log'):
  30.             checkpoint = None
  31.         
  32.         
  33.         def fetch_log(c):
  34.             prompt = c._get_prompt_allowed()
  35.             c._set_prompt_allowed(False)
  36.             c._connect()
  37.             (tmpfd, tmpfname) = tempfile.mkstemp()
  38.             os.close(tmpfd)
  39.             success = False
  40.             
  41.             try:
  42.                 c.getFile('/admin/log/error_log', tmpfname)
  43.                 success = True
  44.             except cups.HTTPError:
  45.                 
  46.                 try:
  47.                     os.remove(tmpfname)
  48.                 except OSError:
  49.                     pass
  50.                 except:
  51.                     None<EXCEPTION MATCH>OSError
  52.                 
  53.  
  54.                 None<EXCEPTION MATCH>OSError
  55.  
  56.             c._set_prompt_allowed(prompt)
  57.             if success:
  58.                 return tmpfname
  59.  
  60.         self.authconn = self.troubleshooter.answers['_authenticated_connection']
  61.         if checkpoint != None:
  62.             self.op = TimedOperation(fetch_log, (self.authconn,), parent = parent)
  63.             tmpfname = self.op.run()
  64.             if tmpfname != None:
  65.                 f = file(tmpfname)
  66.                 f.seek(checkpoint)
  67.                 lines = f.readlines()
  68.                 os.remove(tmpfname)
  69.                 self.answers = {
  70.                     'error_log': map((lambda x: x.strip()), lines) }
  71.             
  72.         
  73.         if answers.has_key('error_log_debug_logging_set'):
  74.             
  75.             try:
  76.                 self.op = TimedOperation(self.authconn.adminGetServerSettings, parent = parent)
  77.                 settings = self.op.run()
  78.             except cups.IPPError:
  79.                 return False
  80.  
  81.             settings[cups.CUPS_SERVER_DEBUG_LOGGING] = '0'
  82.             orig_settings = answers['cups_server_settings']
  83.             settings['MaxLogSize'] = orig_settings.get('MaxLogSize', '2000000')
  84.             success = False
  85.             
  86.             def set_settings(connection, settings):
  87.                 connection.adminSetServerSettings(settings)
  88.                 attempt = 1
  89.                 while attempt <= 5:
  90.                     
  91.                     try:
  92.                         time.sleep(1)
  93.                         connection._connect()
  94.                     continue
  95.                     except RuntimeError:
  96.                         attempt += 1
  97.                         continue
  98.                     
  99.  
  100.                     None<EXCEPTION MATCH>RuntimeError
  101.  
  102.             
  103.             try:
  104.                 self.op = TimedOperation(set_settings, (self.authconn, settings), parent = parent)
  105.                 self.op.run()
  106.                 self.persistent_answers['error_log_debug_logging_unset'] = True
  107.             except cups.IPPError:
  108.                 pass
  109.             except:
  110.                 None<EXCEPTION MATCH>cups.IPPError
  111.             
  112.  
  113.         None<EXCEPTION MATCH>cups.IPPError
  114.         return False
  115.  
  116.     
  117.     def collect_answer(self):
  118.         answers = self.persistent_answers.copy()
  119.         answers.update(self.answers)
  120.         return answers
  121.  
  122.     
  123.     def cancel_operation(self):
  124.         self.op.cancel()
  125.         answers = self.troubleshooter.answers
  126.         factory = answers['_authenticated_connection_factory']
  127.         self.authconn = factory.get_connection()
  128.         self.answers['_authenticated_connection'] = self.authconn
  129.  
  130.  
  131.